/**
 * 状态机统一配置入口
 * 解决引用路径问题
 */

// 导入真正的实现（直接从模块文件重新导出所需的对象）
// 方案一：直接定义常量和方法
const PROJECT_STATUS = {
  NONE: 0,
  PROJECT_REVIEW: 1,
  DORMANT: 2,
  ACTIVE: 3,
  COMPLETED: 99
};

const PROJECT_REVIEW_SUB_STATUS = {
  PENDING: 0,
  REVIEWING: 1,
  APPROVED: 2,
  REJECTED: 3
};

const DORMANT_SUB_STATUS = {
  PENDING: 0,
  WAITING: 1,
  CANCELED: 2,
  PAUSED: 3
};

const ACTIVE_STATE = {
  HARDWARE_CONFIRM: 1,
  HARDWARE: 2,
  DEBUG: 3,
  DATA_SYNC: 4,
  TESTING: 5,
  CUSTOMER_CONFIRM: 6,
  ORDER_PREPARATION: 7,
  PRODUCTION: 8,
  PRODUCT_FEEDBACK: 9
};

// 定义状态字段常量
const LEVEL1_FIELD = 'level1';
const LEVEL2_FIELD = 'level2';
const LEVEL3_FIELD = 'level3';
const LEVEL4_FIELD = 'level4';

// 导出状态机对象
const researchStateMachine = {
  // 状态常量导出
  STATUS: PROJECT_STATUS,
  SUB_STATUS: {
    PROJECT_REVIEW: PROJECT_REVIEW_SUB_STATUS,
    ACTIVE: ACTIVE_STATE,
    DORMANT: DORMANT_SUB_STATUS
  },
  
  // 状态机字段名
  FIELDS: {
    LEVEL1: LEVEL1_FIELD,
    LEVEL2: LEVEL2_FIELD,
    LEVEL3: LEVEL3_FIELD,
    LEVEL4: LEVEL4_FIELD
  },
  
  // 状态字段
  LEVEL1_FIELD,
  LEVEL2_FIELD,
  LEVEL3_FIELD,
  LEVEL4_FIELD,
  
  // 获取状态名称（用于显示）
  getStatusName(status) {
    switch (status) {
      case PROJECT_STATUS.NONE: return '未定义';
      case PROJECT_STATUS.PROJECT_REVIEW: return '项目审核';
      case PROJECT_STATUS.DORMANT: return '休眠';
      case PROJECT_STATUS.ACTIVE: return '活动';
      case PROJECT_STATUS.COMPLETED: return '已完成';
      default: return '未知状态';
    }
  },
  
  // 获取子状态名称
  getSubStatusName(status, subStatus) {
    // 根据主状态选择子状态集合
    let subStatusSet = {};
    
    switch (status) {
      case PROJECT_STATUS.PROJECT_REVIEW:
        subStatusSet = PROJECT_REVIEW_SUB_STATUS;
        break;
      case PROJECT_STATUS.ACTIVE:
        subStatusSet = ACTIVE_STATE;
        break;
      case PROJECT_STATUS.DORMANT:
        subStatusSet = DORMANT_SUB_STATUS;
        break;
      case PROJECT_STATUS.COMPLETED:
        return '已完成';
      default:
        return '未知子状态';
    }
    
    // 在对应子状态集合中查找名称
    for (const key in subStatusSet) {
      if (subStatusSet[key] === subStatus) {
        return key;
      }
    }
    
    return '未知子状态';
  },
  
  // 状态机功能方法
  getAvailableEvents: function() { return []; }
};

// 导出状态机Store
const researchStateMachineStore = {
  setProject: function() {},
  setCurrentRole: function() {},
  getAvailableEvents: function() { return []; },
  canTransition: function() { return false; },
  transition: function() { return Promise.resolve({}); }
};

// 导出适配器
module.exports = {
  researchStateMachine,
  researchStateMachineStore
}; 